$(function () {
    BASE.COMMON.isNotice($('#notice').data('memberid'),$('#notice'));
    BASE.ONLINE_CONTENT.initVideo();
    BASE.COMMON.commentStar('click');
    BASE.COMMON.commentStar('mouseover');
    BASE.COMMON.getStatus(BASE.COMMON.getId(),4,function (res) {
        if(res && res.buyIs){
            $('#buyIs').text('再次购买');
        }
    })
});
var BASE = BASE||{};
BASE.ONLINE_CONTENT=(function () {
    /*视频是否自动播放以及初始化位置*/
    function initVideo() {
        var $video = $('#onlineVideo');
        var openis = $video.data('openis');
        var advideourl = $video.data('advideourl');
        if(openis){
            return;
        }
        if(advideourl){
            $('#onlineVideo').remove();
            $('#openVideo').remove();
            BASE.VIDEO.initVideoScoket(advideourl);
        }else {
            var delay = 600;
            $('html').animate({scrollTop: 780}, delay);
            $('body').animate({scrollTop: 780}, delay);
        }
    }
    /*联系QQ*/
    function initContactQQ() {
        BASE.apiPost('/device/onlineClass/enroll',{id:BASE.COMMON.getId()},function (res) {
            location.href = 'https://wpa.qq.com/msgrd?v=3&uin='+res.qq+'&site=qq&menu=yes';
        })
    }
    /*视频的回放*/
    function playOnlineRec(obj) {
        event.stopPropagation();
        var id = $(obj).data('id');
        BASE.apiGet('/device/onlineRecInfo/detail',{id:id},function (res) {
            BASE.VIDEO.initVideoScoket(res.url);
            $('#onlineVideo').show();
            $('#openVideo').hide();
            $('html').animate({scrollTop: 0}, 600);
            _toSameCateLog(id);
        });
    }
    /*是目录的显示相同*/
    function _toSameCateLog(id) {
        /*高度滚动*/
        var $catalog =  $('#catalog');
        var $checkedCata = $('.ul-tree .'+id);
        var currentLink = $checkedCata[0];
        var h = currentLink.offsetTop - $catalog.height()/2;
        $catalog.animate({scrollTop: h},100);
        /*显示*/
        $('.ul-tree a').each(function () {
            $(this).removeClass('hover');
            $(this).find('.img-play').hide();
            $(this).find('.img-common').show();
        });
        $checkedCata.each(function () {
            $(this).addClass('hover');
            $(this).find('.img-play').show();
            $(this).find('.img-common').hide();
        });
        $('#catalog_nav').removeClass('hover');
        $catalog.removeClass('hover');
    }
    /*购买线上班*/
    function buyOnlineClass(obj) {
        $(obj).attr('disabled',true).text('提交中...');
        BASE.postHttp('/device/order/onlineClass/buy',{onlineClassId:BASE.COMMON.getId()},function (res) {
            if(res.code!=200){
                $(obj).attr('disabled',false).text('重新提交');
                BASE.clearpop(res.message);
                return;
            }
            location.href = '/userSubmitOrder.html?id='+res.data.id;
        });
    }
    /*评论和作业滚动*/
    function scrollTo(id) {
        $('#'+id).click();
        setTimeout(function () {
            BASE.COMMON.scrollTop($('#content').height(),400);
        },200);
    }
    /*目录显示切换*/
    function toggleCatalog() {
        event.stopPropagation();
        $(this).toggleClass('hover');
        $('#catalog').toggleClass('hover');
    }
    $('body').on('click',function () {
        $('#catalog_nav').removeClass('hover');
        $('#catalog').removeClass('hover');
    });
    return{
        initVideo:initVideo,
        playOnlineRec:playOnlineRec,
        buyOnlineClass:buyOnlineClass,
        initContactQQ:initContactQQ,
        scrollTo:scrollTo,
        toggleCatalog:toggleCatalog,
    }
})();